﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Drawing;

namespace QLCONGNOLIBS.Models
{
    public class ImageModels
    {
        /// <summary>
        /// ConvertImageToByte
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public byte[] ConvertImageToByte(string filePath)
        {
            try
            {
                FileStream objStream = new FileStream(
                filePath, FileMode.Open, FileAccess.Read);
                BinaryReader objReader = new BinaryReader(objStream);
                byte[] byImages = objReader.ReadBytes((int)objStream.Length);

                objReader.Close();
                objStream.Close();

                return byImages;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally { }
        }

        /// <summary>
        /// ConvertByteToImage
        /// </summary>
        /// <param name="byImages"></param>
        /// <returns></returns>
        public Image ConvertByteToImage(byte[] byImages)
        {
            MemoryStream objMStream;
            try
            {
                objMStream = new MemoryStream(byImages);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }
            return Image.FromStream(objMStream);
        }
    }
}
